package com.lagou.mr;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.CombineTextInputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class NumDriver {

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);
        job.setJarByClass(NumDriver.class);

        job.setMapperClass(NumMapper.class);
        job.setReducerClass(NumReducer.class);

        job.setMapOutputKeyClass(NumBean.class);
        job.setMapOutputValueClass(NullWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NumBean.class);

        //因有四个小文件需要处理，特将此合并为一个分区，以便分区进行全排序
        CombineTextInputFormat.setMaxInputSplitSize(job, 4194304);
        job.setInputFormatClass(CombineTextInputFormat.class);

        FileInputFormat.setInputPaths(job, new Path("d:/input/datas"));
        FileOutputFormat.setOutputPath(job, new Path("d:/output"));

        boolean flag = job.waitForCompletion(true);
        System.exit(flag ? 0 : 1);
    }
}
